package it.uniroma3.gaia.sama.schemaExchangeGenerator;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Combination<T extends Object> implements Iterable<T> {

	private List<T> elements;
	
	public Combination() {
		this.setElements(new LinkedList<T>());
	}
	
	@Override
	public Iterator<T> iterator() {
		return this.elements.iterator();
	}
	
	public boolean add(T element){
		if(this.elements.contains(element))
			return false;
		return this.elements.add(element);
	}
	
	public boolean addAll(Combination<T> elements){
		boolean result= true;
		for(T element : elements){
			if(result)
				result = this.add(element);
			else
				return result;
		}
		return result;
	}
	
	@Override
	public boolean equals(Object o){
		Combination<T> c = (Combination<T>)o;
		return (c.getElements().containsAll(this.elements) && this.elements.containsAll(c.getElements()));
	}

	public void setElements(List<T> elements) {
		this.elements = elements;
	}

	public List<T> getElements() {
		return elements;
	}
	
	public int size(){
		return this.elements.size();
	}
	
	public boolean contains(T element){
		return this.elements.contains(element);
	}

	@Override
	public String toString(){
		return this.elements.toString();
	}
	
}
